<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="@{/}" />
    <meta charset="UTF-8">
    <title>模块练习页面</title>
</head>
<body>
    <h1>模块练习页面</h1>
    <a href="findUsers"><button>点击展现用户信息</button></a>
    <hr>
    <!--编辑表格数据-->
    <table width="800px" border="1px" cellpadding="0" cellspacing="0" align="center">
        <tr>
            <th>序号</th>
            <th>ID号</th>
            <th>用户名</th>
            <th>邮箱</th>
            <th>操作</th>
        </tr>
        <tr>
           <th colspan="5" th:if="${#lists.isEmpty(userList)}">
          <!-- <th colspan="5" th:if="${#lists.size(userList)}">-->
                <h3>请添加用户信息</h3>
            </th>
        </tr>
        <tr th:each="user,status:${userList}">
            <th th:text="${status.count}">1</th>
            <th th:text="${user.id}">1001</th>
            <th th:text="${user.username}">张三</th>
            <th th:text="${user.email}">888@qq.com</th>
            <th>
                <!--如果使用th:href的用法 则base标签将不起作用
                    th:href="@{/findUserById( id=${对象.属性}, name=${对象.属性})}"
                -->
                <a th:href="@{/findUserById(id=${user.userid})}"><button>编辑</button></a>
                <a th:href="@{/deleteUserById(id=${user.userid})}"><button>删除</button></a>
            </th>
        </tr>
    </table>
    <hr>
    <form action="addUser" method="post">
        <table align="center">
            <tr align="center">
                <td colspan="2">
                    <h3>新增用户</h3>
                </td>
            </tr>
            <tr>
                <td>用户名:</td>
                <td><input type="text" name="username" /></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="password"/></td>
            </tr>
            <tr>
                <td>邮箱:</td>
                <td><input type="text" name="email" /></td>
            </tr>
            <tr>
                <td th:cols="2">
                    <button type="submit">提交</button>
                </td>
            </tr>
        </table>
    </form>
    <hr>
    <form action="updateUser" method="post">
        <table align="center"  th:unless="${updateUser == null}">
            <!--通过隐藏域的方式 实现主键的提交-->
            <input type="hidden" name="id" th:value="${updateUser.id}"/>
            <tr align="center">
                <td colspan="2">
                    <h3>修改用户</h3>
                </td>
            </tr>
            <tr>
                <td>用户名:</td>
                <td><input type="text" name="username" th:value="${updateUser.username}"/></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="password" placeholder="默认密码不修改,如果赋值则修改"/></td>
            </tr>
            <tr>
                <td>邮箱:</td>
                <td><input type="text" name="email" th:value="${updateUser.email}"/></td>
            </tr>
            <tr>
                <td th:cols="2">
                    <button type="submit">提交</button>
                </td>
            </tr>
        </table>
    </form>

</body>
</html>